define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'teacher_choose/index' + location.search,
                    del_url: 'teacher_choose/del',
                    multi_url: 'teacher_choose/multi',
                    import_url: 'teacher_choose/import',
                    table: 'teacher_choose',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                showToggle: false,
                exportTypes : ['excel'],
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search : false,
                commonSearch : false,
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.nickname',operate: 'LIKE', title: __('User_id'), width: '200',formatter:function(v,row){
                                var html = '<div style="display:flex"><img width="60px" height="60px" src="'+Fast.api.cdnurl(row.user.avatar)+'" /><p style="text-align:left;line-height:20px;margin-top:5px;margin-left:10px">ID:'+row.user.id+'<br/>'+row.user.nickname+'<br/>'+row.user.mobile+'</p></div>';
                                return html;
                            }
                        },
                        {field: 'addr_text', title: __('Addr'), formatter:function(value,row,index){
                                return value[0]+value[1];
                            }},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'student', title: __('Student'), operate: 'LIKE'},
                        {field: 'sex', title: __('Sex'), operate: 'LIKE'},
                        {field: 'grade', title: __('Grade'), operate: 'LIKE'},
                        {field: 'subject', title: __('Subject')},
                        {field: 'state', title: __('State'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'learn_date', title: __('Learn_date'), operate: 'LIKE'},
                        {field: 'learn_time', title: __('Learn_time'), operate: 'LIKE'},
                        {field: 'teacher_sex', title: __('Teacher_sex'), operate: 'LIKE'},
                        {field: 'teacher_type', title: __('Teacher_type'), operate: 'LIKE'},
                        {field: 'demand', title: __('Demand'), operate: 'LIKE'},
                        {field: 'is_audit', title: __('Is_audit'),searchList: {'0':'未处理','1':'已处理'},formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons :[
                                {
                                    name: 'handle',
                                    text: __('已处理'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    visible : function (row){
                                        if(row.is_audit){
                                            return false;
                                        }else{
                                            return true;
                                        }
                                    },
                                    url: 'teacher_choose/handle',
                                    refresh: true
                                },
                            ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
